package com.loren.demo07.simple.config;

import com.loren.demo07.simple.handler.CustomSimpleMessageHandler;
import com.loren.demo07.simple.web.interceptor.CustomSimpleHandshakeInterceptor;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
@AllArgsConstructor
public class SimpleConfig implements WebSocketConfigurer {

    private final CustomSimpleMessageHandler customSimpleMessageHandler;

    private final CustomSimpleHandshakeInterceptor customSimpleHandshakeInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(this.customSimpleMessageHandler, "/simple/websocket").addInterceptors(this.customSimpleHandshakeInterceptor);
    }
}